﻿using System.Collections.Generic;
using System.Linq;

namespace DotNetCommon;

/// <summary>
/// 手机号码前缀
/// </summary>
public static class CellPhonePrefix
{
    /// <summary>
    /// 区号和地区名称对照表(可能两个国家对应一个区号, 如: 加拿大和美国都是 "+1")
    /// </summary>
    public static readonly IReadOnlyList<(string prefix, string area)> Mappings =
    [
        ("+86","中国大陆"),
        ("+852","香港"),
        ("+853","澳门"),
        ("+886","台湾"),
        ("+82","韩国"),
        ("+81","日本"),
        ("+1","美国"),
        ("+1","加拿大"),
        ("+44","英国"),
        ("+65","新加坡"),
        ("+60","马来西亚"),
        ("+66","泰国"),
        ("+84","越南"),
        ("+63","菲律宾"),
        ("+62","印度尼西亚"),
        ("+39","意大利"),
        ("+7","俄罗斯"),
        ("+64","新西兰"),
        ("+31","荷兰"),
        ("+46","瑞典"),
        ("+61","澳大利亚"),
        ("+380","乌克兰"),
        ("+33","法国"),
        ("+49","德国"),
        ("+93","阿富汗"),
        ("+355","阿尔巴尼亚"),
        ("+213","阿尔及利亚"),
        ("+1684","东萨摩亚(美)"),
        ("+376","安道尔"),
        ("+244","安哥拉"),
        ("+1264","安圭拉岛(英)"),
        ("+1268","安提瓜和巴布达"),
        ("+54","阿根廷"),
        ("+374","亚美尼亚"),
        ("+297","阿鲁巴岛"),
        ("+43","奥地利"),
        ("+994","阿塞拜疆"),
        ("+973","巴林"),
        ("+880","孟加拉国"),
        ("+1246","巴巴多斯"),
        ("+375","白俄罗斯"),
        ("+32","比利时"),
        ("+501","伯利兹"),
        ("+229","贝宁"),
        ("+1441","百慕大群岛(英)"),
        ("+975","不丹"),
        ("+591","玻利维亚"),
        ("+387","波斯尼亚和黑塞哥维那"),
        ("+267","博茨瓦纳"),
        ("+55","巴西"),
        ("+359","保加利亚"),
        ("+226","布基纳法索"),
        ("+257","布隆迪"),
        ("+237","喀麦隆"),
        ("+238","佛得角"),
        ("+1345","开曼群岛(英)"),
        ("+236","中非"),
        ("+235","乍得"),
        ("+56","智利"),
        ("+61","圣诞岛"),
        ("+61","科科斯岛"),
        ("+57","哥伦比亚"),
        ("+269","科摩罗"),
        ("+242","刚果"),
        ("+682","科克群岛(新)"),
        ("+506","哥斯达黎加"),
        ("+385","克罗地亚"),
        ("+53","古巴"),
        ("+357","塞浦路斯"),
        ("+420","捷克"),
        ("+45","丹麦"),
        ("+253","吉布提"),
        ("+1767","多米尼克国"),
        ("+1809","多米尼加共和国"),
        ("+593","厄瓜多尔"),
        ("+20","埃及"),
        ("+503","萨尔瓦多"),
        ("+240","赤道几内亚"),
        ("+291","厄立特里亚"),
        ("+372","爱沙尼亚"),
        ("+251","埃塞俄比亚"),
        ("+500","福克兰群岛"),
        ("+298","法罗群岛(丹)"),
        ("+679","斐济"),
        ("+358","芬兰"),
        ("+689","法属波里尼西亚"),
        ("+241","加蓬"),
        ("+220","冈比亚"),
        ("+995","格鲁吉亚"),
        ("+233","加纳"),
        ("+350","直布罗陀(英)"),
        ("+30","希腊"),
        ("+299","格陵兰岛"),
        ("+1473","格林纳达"),
        ("+590","瓜德罗普岛(法)"),
        ("+1671","关岛(美)"),
        ("+502","危地马拉"),
        ("+224","几内亚"),
        ("+245","几内亚比绍"),
        ("+592","圭亚那"),
        ("+509","海地"),
        ("+504","洪都拉斯"),
        ("+36","匈牙利"),
        ("+354","冰岛"),
        ("+91","印度"),
        ("+98","伊郎"),
        ("+964","伊拉克"),
        ("+353","爱尔兰"),
        ("+972","以色列"),
        ("+225","科特迪瓦"),
        ("+1876","牙买加"),
        ("+962","约旦"),
        ("+855","柬埔塞"),
        ("+7","哈萨克斯坦"),
        ("+254","肯尼亚"),
        ("+686","基里巴斯"),
        ("+965","科威特"),
        ("+996","吉尔吉斯斯坦"),
        ("+856","老挝"),
        ("+371","拉脱维亚"),
        ("+961","黎巴嫩"),
        ("+266","莱索托"),
        ("+231","利比里亚"),
        ("+218","利比亚"),
        ("+423","列支敦士登"),
        ("+370","立陶宛"),
        ("+352","卢森堡"),
        ("+389","马其顿"),
        ("+261","马达加斯加"),
        ("+265","马拉维"),
        ("+960","马尔代夫"),
        ("+223","马里"),
        ("+356","马耳他"),
        ("+692","马绍尔群岛"),
        ("+596","马提尼克(法)"),
        ("+222","毛里塔尼亚"),
        ("+230","毛里求斯"),
        ("+262","马约特岛"),
        ("+52","墨西哥"),
        ("+691","密克罗尼西亚(美)"),
        ("+377","摩纳哥"),
        ("+976","蒙古"),
        ("+1664","蒙特塞拉特岛(英)"),
        ("+212","摩洛哥"),
        ("+258","莫桑比克"),
        ("+95","缅甸"),
        ("+264","纳米比亚"),
        ("+674","瑙鲁"),
        ("+977","尼泊尔"),
        ("+599","荷属安的列斯群岛"),
        ("+687","新喀里多尼亚群岛(法)"),
        ("+505","尼加拉瓜"),
        ("+227","尼日尔"),
        ("+234","尼日利亚"),
        ("+683","纽埃岛(新)"),
        ("+672","诺福克岛(澳)"),
        ("+850","朝鲜"),
        ("+1670","马里亚纳群岛"),
        ("+47","挪威"),
        ("+968","阿曼"),
        ("+92","巴基斯坦"),
        ("+680","帕劳(美)"),
        ("+507","巴拿马"),
        ("+675","巴布亚新几内亚"),
        ("+595","巴拉圭"),
        ("+51","秘鲁"),
        ("+48","波兰"),
        ("+351","葡萄牙"),
        ("+1","波多黎各(美)"),
        ("+974","卡塔尔"),
        ("+373","摩尔多瓦"),
        ("+262","留尼汪岛"),
        ("+40","罗马尼亚"),
        ("+250","卢旺达"),
        ("+247","阿森松(英)"),
        ("+290","圣赫勒拿"),
        ("+1869","圣克里斯托弗和尼维斯"),
        ("+1758","圣卢西亚"),
        ("+508","圣皮埃尔岛及密克隆岛"),
        ("+1784","圣文森特岛(英)"),
        ("+685","西萨摩亚"),
        ("+378","圣马力诺"),
        ("+239","圣多美和普林西比"),
        ("+966","沙特阿拉伯"),
        ("+221","塞内加尔"),
        ("+248","塞舌尔"),
        ("+232","塞拉利昂"),
        ("+421","斯洛伐克"),
        ("+386","斯洛文尼亚"),
        ("+677","所罗门群岛"),
        ("+252","索马里"),
        ("+27","南非"),
        ("+34","西班牙"),
        ("+94","斯里兰卡"),
        ("+249","苏丹"),
        ("+597","苏里南"),
        ("+268","斯威士兰"),
        ("+41","瑞士"),
        ("+963","叙利亚"),
        ("+992","塔吉克斯坦"),
        ("+1242","巴哈马国"),
        ("+14397","梵蒂冈"),
        ("+228","多哥"),
        ("+676","汤加"),
        ("+1868","特立尼达和多巴哥"),
        ("+216","突尼斯"),
        ("+90","土耳其"),
        ("+993","土库曼斯坦"),
        ("+1649","特克斯和凯科斯群岛(英)"),
        ("+688","图瓦卢"),
        ("+256","乌干达"),
        ("+44","英国"),
        ("+255","坦桑尼亚"),
        ("+598","乌拉圭"),
        ("+998","乌兹别克斯坦"),
        ("+678","瓦努阿图"),
        ("+58","委内瑞拉"),
        ("+1340","维尔京群岛(英)"),
        ("+967","也门"),
        ("+381","南斯拉夫"),
        ("+260","赞比亚"),
        ("+259","桑给巴尔"),
        ("+263","津巴布韦")
    ];

    private static List<string> _prefix = Mappings.Select(i => i.prefix).OrderByDescending(i => i.Length).Distinct().ToList();

    /// <summary>
    /// 前缀集合
    /// </summary>
    public static List<string> Prefix => [.. _prefix];
}
